<?php

use yii\widgets\ActiveForm;
use common\helpers\Url;
use common\enums\StatusEnum;

$form = ActiveForm::begin([
    'id' => $model->formName(),
    'enableAjaxValidation' => true,
    'class' => 'form-horizontal',
    'validationUrl' => Url::to(['ajax-edit', 'id' => $model['id']]),
    'fieldConfig' => [
        'template' => "<div class='col-sm-3 text-right'>{label}</div><div class='col-sm-9'>{input}\n{hint}\n{error}</div>",
    ]
]);
?>

    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true" onclick="history.go(-1)">×</span></button>
            <h4 class="modal-title">基本信息</h4>
        </div>
        <div class="modal-body">
            <?= $form->field($model, 'title')->textInput() ?>
            <?= $form->field($model, 'image')->widget('common\widgets\webuploader\Files', [
                'type' => 'files',
                'config' => [ // 配置同图片上传
                    // 'server' => \yii\helpers\Url::to(['file/files']), // 默认files 支持videos/voices/images方法验证
                    'pick' => [
                        'multiple' => false,
                    ]
                ]
            ]);?>

<!--             自定义配置参数用法-->
            <?= $form->field($model, 'content')->widget(\common\widgets\ueditor\UEditor::class, [
                'config' => [

                ],
                'formData' => [
                    'drive' => 'local', // 默认本地 支持qiniu/oss/cos 上传
                    'poster' => false, // 上传视频时返回视频封面图，开启此选项需要安装 ffmpeg 命令
                    'thumb' => [ // 图片缩略图
                        [
                            'width' => 100,
                            'height' => 100,
                        ],
                    ]
                ],
            ]) ?>
            <?= $form->field($model, 'source')->textInput() ?>
            <?= $form->field($model, 'editor')->textInput() ?>
            <?= $form->field($model, 'sort')->textInput() ?>
            <?= $form->field($model, 'fabulous')->radioList(StatusEnum::fabulous()) ?>
            <?= $form->field($model, 'collection')->radioList(StatusEnum::collection()) ?>
            <?= $form->field($model, 'status')->radioList(StatusEnum::getMap()) ?>
        </div>
        <div class="modal-footer">
            <span class="btn btn-white" onclick="history.go(-1)">返回</span>
            <button class="btn btn-primary" type="submit">保存</button>
        </div>
    </div>

<?php ActiveForm::end(); ?>
<script type="text/javascript">
    // 提交表单时候触发
    function sendForm() {
        var status = "<?= Yii::$app->user->id == $model->id ? true : false;?>";
        if (status) {
            var src = $('input[name="Manager[image]"]').val();
            if (src) {
                $('.image', window.parent.document).attr('src', src);
            }
        }
    }
</script>

